package com.example.demo.controller;

import com.example.demo.common.lang.Result;
import com.example.demo.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
public class TestController {
    @Resource
    private SysUserService sysUserService;
    @Resource
    BCryptPasswordEncoder bCryptPasswordEncoder;
    @PreAuthorize("hasRole('admin')")
    @GetMapping("/test")

    public Result test(){
        return Result.succ(sysUserService.list());
    }

    @PreAuthorize("hasAuthority('sys:user:list')")
    @GetMapping("/test/password")
     public Result pass(){
        //加密之后的密码
        String passwd = bCryptPasswordEncoder.encode("111111");
        boolean matches = bCryptPasswordEncoder.matches("111111", passwd);
        System.out.println("匹配结果："+matches);
        return Result.succ(passwd);
    }



}
